package org.jeese.common.utils;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

/**
 * MD5加密工具
 */
/**
 * @Description:
 * @Package:org.jeese.utils
 * @author:wubc
 * @version:1.0
 * @date:2017年10月30日-下午1:53:27
 * @Copyright:2017 Inc. All rights reserved.
 */
public class EncryptUtils {

	private static final String SALT = "YWRtaW4=";
	
	private static final String ALGORITH_NAME = "md5";
	
	private static final int HASH_ITERATIONS = 2;

	/**
	 * 使用md5生成加密后的密码
	 * @param user
	 * @return
	 */
	public static String encrypt(String pswd) {
		String newPassword = new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(SALT), HASH_ITERATIONS).toHex();
		return newPassword;
	}
	
	/**
	 * 使用md5生成加密后的密码
	 * @param user
	 * @return
	 */
	public static String encrypt(String username, String pswd) {
		return new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(username), HASH_ITERATIONS).toHex();
	}
	public static void main(String[] args) {
		System.out.println(encrypt("admin","1"));
	}
	
}
